package logic

import (
	"context"
	"errors"
	"video/mysql/model"

	"video/videorpc/internal/svc"
	"video/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentDelLogic {
	return &CommentDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论管理
func (l *CommentDelLogic) CommentDel(in *videorpc.CommentDelRequest) (*videorpc.CommentDelResponse, error) {
	// todo: add your logic here and delete this line

	var comment model.Comment
	model.DB.Debug().Where("id = ?", in.CommentId).Find(&comment)
	if comment.ID == 0 {
		return nil, errors.New("未找到该评论,删除失败")
	}
	model.DB.Debug().Delete(&comment)

	return &videorpc.CommentDelResponse{}, nil
}
